<template>
  <div class="import-button">
    <el-button type="warning" icon="el-icon-upload2" @click="handleExport()">
      导出
    </el-button>
    <el-button type="success" icon="el-icon-download" @click="handleImports()"
      >导入</el-button
    >
    <Import :type="type" />
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  components: {
    Import: () => import('./Import.vue'),
  },
  data() {
    return {
      title: '',
      templatePort: '', //模板接口
      exportPort: '', //导出接口
      fileTemp: '',
      busEmit: '',
    }
  },
  props: {
    type: {
      type: String,
      default: 'course',
    },
  },
  computed: mapGetters(['userId', 'userType', 'deptFullData']),
  mounted() {
    this.init()
    this.$bus.$on('sendDeptId', this.init)
  },
  beforeDestroy() {
    this.$bus.$off('sendDeptId')
  },
  methods: {
    init(id) {
      let deptId = ''
      if (id) {
        deptId = id
      } else {
        deptId = this.userType != 1 ? this.deptFullData.childList[0].id : ''
      }
      //导出校本资源
      if (this.type == 'course') {
        this.exportPort = '/sysCourseSource/export?scope=' + deptId
      }
      //导出教学班次
      if (this.type == 'teaching') {
        this.exportPort = '/eduTeaching/export'
      }
      //导出校区部门
      if (this.type == 'unit') {
        this.exportPort = '/tbSysDept/export?scope=' + deptId
      }
      //导出用户
      if (this.type == 'user') {
        this.exportPort = '/tbSysUser/export?isChildUser=1&deptId=' + deptId
      }
    },
    //导出数据
    handleExport() {
      window.location.href = this.baseURL + this.exportPort
    },
    //导入弹窗
    handleImports() {
      this.$bus.$emit('showDialogScoreRuleAdd')
    },
  },
}
</script>
<style scoped>
.import-button button {
  float: right;
  margin-left: 10px;
}
</style>